package cn.schoolwow.util.module.check.instance.flow;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class CheckInstanceIdFieldFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        Object idFieldValue = flowContext.getData("idFieldValue");
        String message = (String) flowContext.checkData("message");

        if(null==idFieldValue){
            throw new IllegalArgumentException(message+"的值为空");
        }
        if(idFieldValue instanceof Integer){
            Integer integer = (Integer) idFieldValue;
            if(integer<=0){
                throw new IllegalArgumentException(message+"的值小于0!当前值:"+integer);
            }
        }else if(idFieldValue instanceof Long){
            Long aLong = (Long) idFieldValue;
            if(aLong<=0){
                throw new IllegalArgumentException(message+"的值小于0!当前值:"+aLong);
            }
        }else{
            throw new IllegalArgumentException(message+"的字段类型不为整型!当前类型:"+idFieldValue.getClass().getName());
        }
    }

    @Override
    public String name() {
        return "实例-检查id字段的值是否大于0";
    }
}
